package org.easy.core.util;

import java.util.Random;

public class RandomStringGenerator {
    private static final String CHAR_LOWER = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static void main(String[] args) {
        int length = 9; // 这里设置你想要的字符串长度
        System.out.println("Generated random string: " + generateRandomString(length));
    }

    /**
     * 随机取9个
     *
     * @param length
     * @return
     */
    public static String generateRandomString(int length) {
        if (length < 1) throw new IllegalArgumentException();

        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();

        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHAR_LOWER.length());
            sb.append(CHAR_LOWER.charAt(index));
        }

        return sb.toString();
    }
}
